//package com.old.service.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.old.service.VoskService;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.core.io.Resource;
//import org.springframework.stereotype.Service;
//import org.vosk.Model;
//import org.vosk.Recognizer;
//
//import javax.sound.sampled.AudioSystem;
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStream;
//
//@Service
//public class VoskServiceImpl implements VoskService {
//    private static final Model MODEL;
//
//    static {
//        try {
////            Resource resource = new ClassPathResource("/bin/vosk-model-small-cn-0.22");//精简中文模型，速度快，准确度低
////             Resource resource = new ClassPathResource("/static/vosk-model-cn-0.22");//高精度中文模型，速度慢，准确度高
////            File file = resource.getFile();
////            MODEL = new Model(file.getAbsolutePath());
//            MODEL = new Model("/springBoot/vosk-model-small-cn-0.22");//精简中文模型，速度快，准确度低
////            MODEL = new Model("D:\\vosk-model-small-cn-0.22");//精简中文模型，速度快，准确度低
////            MODEL = new Model("D:\\vosk-model-cn-0.22");//高精度中文模型，速度慢，准确度高
//
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//
//    @Override
//    public String transcribe(String audioPath) throws Exception {
//        try (Recognizer recognizer = new Recognizer(MODEL, 16000.0f);
//             InputStream ais = AudioSystem.getAudioInputStream(new File(audioPath))) {
//
//            byte[] buffer = new byte[4096];
//            int bytesRead;
//            while ((bytesRead = ais.read(buffer)) >= 0) {
//                recognizer.acceptWaveForm(buffer, bytesRead);
//            }
//
//            JSONObject json = JSON.parseObject(recognizer.getFinalResult()); // 使用 FastJSON 的解析方法
//            return json.getString("text");
//        }
//
//    }
//}
